<?php
// Global include file. 

define("SERVER_DEV", "dev"); // Development machine
define("SERVER_PRODUCTION", "production"); // Hosting

ini_set("mbstring.language", "Neutral"); // force to use UTF8 encoding for mb_* functions

// Detect server - $_SERVER["DOCUMENT_ROOT"]
$SERVER_ID = NULL;
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
	$SERVER_ID = SERVER_DEV;
} else {
	$SERVER_ID = SERVER_PRODUCTION;
}

// Detect root folder.
define("DIR_ROOT", dirname(__FILE__) . DIRECTORY_SEPARATOR);

if($SERVER_ID == SERVER_DEV) { // development machine
	$URL_ROOT = "/karma/";  // If updated, you must update .htaccess
	$MYSQL_HOST = "localhost";	$MYSQL_USER = "root";	$MYSQL_PASS = "???"; $MYSQL_DB = "??"; $MYSQL_PORT = 3306;
	$DEBUG = true;
}else if($SERVER_ID == SERVER_PRODUCTION) { // production
	$URL_ROOT = "/"; // If updated, you must update .htaccess
	$MYSQL_HOST = "localhost";	$MYSQL_USER = "root";	$MYSQL_PASS = "???"; $MYSQL_DB = "??"; $MYSQL_PORT = 3306;
} else {
	throw new Exception("Unsupported server: " . $SERVER_ID);
}

// File paths
define("DIR_LIBS", DIR_ROOT . "_LIBS" . DIRECTORY_SEPARATOR);
define("DIR_INC", DIR_ROOT . "_INC" . DIRECTORY_SEPARATOR);
ini_set('include_path', DIR_INC . PATH_SEPARATOR . DIR_ROOT . PATH_SEPARATOR . DIR_LIBS . PATH_SEPARATOR . ini_get('include_path'));
// print("Path: " . ini_get('include_path'));

// URL paths
//  *** URL directories, keys starting with 'URL_DIR_', values including trailing slash.
$URL_DIR_CSS = $URL_ROOT."_CSS/";
$URL_DIR_JS = $URL_ROOT."_JS/";
$URL_DIR_IMG = $URL_ROOT."_IMG/";

// *** URL pages, keys starting with 'URL_'.
$URL_PAGE_LOGIN = $URL_ROOT."user/index.php";
$URL_PAGE_TERMS = $URL_ROOT."home/terms.php";
$URL_PAGE_PRIVACY = $URL_ROOT."home/privacy.php";

//require_once 'i_navigation.php';
//
//$MENU_ROOT = 
//new MenuItem("root", NULL, null, null, null, "Athena Framework", null, array(
//	new MenuItem("athenajava", "java/index.php", null, null, null, "Athena for Java", null, array(
//		new MenuItem("athenajava_overview", "java/index.php", null, null, null, "Overview", null),
//
//		new MenuItem("athenajava_mt-tut", "java/multitenancy-tutorial.php", null, null, null, "Cloud SaaS Tutorial", null, array(
//			new MenuItem("athenajava_mt-tut-0", "java/multitenancy-tutorial.php", null, null, null, "Overview", null),
//			new MenuItem("athenajava_mt-tut-1", "java/multitenancy-tutorial.php?part=1", null, null, null, "1. Multitenacy Basics", null),
//			new MenuItem("athenajava_mt-tut-2", "java/multitenancy-tutorial.php?part=2", null, null, null, "2. Project Setup and Application Coding", null),
//			new MenuItem("athenajava_mt-tut-3", "java/multitenancy-tutorial.php?part=3", null, null, null, "3. Org, User Entities and Admin Page", null),
//			new MenuItem("athenajava_mt-tut-4", "java/multitenancy-tutorial.php?part=4", null, null, null, "4. Login Page and UserContext Binding", null)
//		)),
//	)),	
//	new MenuItem("support_services", "support_services/index.php", null, null, null, "Support and Services", null, array(
//		new MenuItem("support_services_index", "support_services/index.php", null, null, null, "Overview", null)
//	))
//));

// always use session.
session_start();

function redirectIfNotLoggedIn() {
	if($_SESSION['user'] == null) {
		header("Location: ${URL_ROOT}login.php");
		exit;
	}
}

require_once 'i_page.php';
?>